<template>
  <div class="main-content">
    <!-- 列表页 -->
    <div v-if="showFlag">
      <el-form :inline="true" :model="searchForm" class="form-content">
        <el-row :gutter="20" class="slt"
                :style="{justifyContent:'center'}">
          <el-form-item label='教师姓名'>
            <el-input v-model="searchForm.mentorname" placeholder="教师姓名"
                      clearable></el-input>
          </el-form-item>

          <el-form-item label='工号'>
            <el-input v-model="searchForm.mentoraccount" placeholder="工号"
                      clearable></el-input>
          </el-form-item
          >
          <el-form-item>
            <el-button icon="el-icon-search"
                       type="success" @click="search()"
            >
              {{ '查询' }}
            </el-button>
          </el-form-item>

        </el-row>
        <el-row class="ad"
                :style="{display: 'flex',
                justifyContent:'center'}">
          <!--          <el-form-item style="margin: 10px">-->
          <!--            <el-button-->
          <!--                type="warning"-->
          <!--                icon="el-user"-->
          <!--                @click="chartDialog()"-->
          <!--            >-->
          <!--              {{'我的选择'}}-->
          <!--            </el-button>-->
          <!--          </el-form-item>-->

          <transition name="fade">
            <div v-if="hasSubmit === ''">

            </div>
            <!--    临时措施使不在数据获取前显示为空       -->
            <div v-else-if='hasSubmit'
                 style="text-align: center; width: 80%; display: flex; justify-content: center; align-items: center">
              您已提交志愿, 请耐心等待导师回复
            </div>

            <div v-else-if="!hasSubmit" style=" width: 80%; display: flex;">
              <div style=" width: 30%;padding-left: 2%;padding-top: 5px">
                第一志愿 : {{ transData.firstname ? transData.firstname : '无数据' }}
                <el-button size="small" @click="cancelFi()">
                  取消选择
                </el-button>
              </div>
              <div style="width: 30%;padding-left: 2%;padding-top: 5px">
                第二志愿 : {{ transData.secondname ? transData.secondname : '无数据' }}
                <el-button size="small" @click="cancelSe()">
                  取消选择
                </el-button>
              </div>
              <div style="width: 30%;padding-left: 2%;padding-top: 5px">
                第三志愿 : {{ transData.thirdname ? transData.thirdname : '无数据' }}
                <el-button size="small" @click="cancelTh()">
                  取消选择
                </el-button>
              </div>

              <div slot="footer" style="width: 20%;padding-bottom: 10px">
                <el-button
                    style="margin-left: 100px;height: 35px ;background-color: #01d583;color: #ffffff;font-weight: 545"
                    v-if="hasChoice.length < 3 && !hasSubmit"
                    :disabled="true"
                >
                  提交志愿
                </el-button>
                <el-button
                    style="margin-left: 100px;height: 35px ;background-color: #01d583;color: #ffffff;font-weight: 545"
                    v-else-if="!hasSubmit"
                    type="primary"
                    @click="submit()">确 定
                </el-button>
              </div>
            </div>
          </transition>

        </el-row>
      </el-form>
      <div class="table-content">
        <el-table class="tables" :size="contents.tableSize" :show-header="contents.tableShowHeader"
                  :header-row-style="headerRowStyle" :header-cell-style="headerCellStyle"
                  :border="contents.tableBorder"
                  :fit="contents.tableFit"
                  :stripe="contents.tableStripe"
                  :row-style="rowStyle"
                  :cell-style="cellStyle"
                  :style="{width: '100%',fontSize:contents.tableContentFontSize,color:contents.tableContentFontColor}"
                  v-if=true
                  :data="dataList"
                  v-loading="dataListLoading"
                  @selection-change=selectionChangeHandler>
          <el-table-column v-if="contents.tableSelection"
                           type="selection"
                           header-align="center"
                           align="center"
                           width="50">
          </el-table-column>
          <el-table-column label="索引" type="index" width="50" :index="indexMethod"/>
<!--          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"-->
<!--                           width="130px"-->
<!--                           prop="mentoraccount"-->
<!--                           header-align="center"-->
<!--                           label="工号">-->
<!--            <template slot-scope="scope">-->
<!--              {{ scope.row.mentoraccount }}-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           prop="mentorname"
                           header-align="center"
                           label="教师姓名">
            <template slot-scope="scope">
              {{ scope.row.mentorname }}
            </template>
          </el-table-column>
          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           prop="gender"
                           header-align="center"
                           label="性别">
            <template slot-scope="scope">
              {{ scope.row.gender }}
            </template>
          </el-table-column>
          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           prop="mentorcollege"
                           header-align="center"
                           label="学院">
            <template slot-scope="scope">
              {{ scope.row.mentorcollege }}
            </template>
          </el-table-column>
          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           prop="applicationCount"
                           header-align="center"
                           label="已选择该导师人数">
            <template slot-scope="scope">
              {{ scope.row.applicationCount }}
            </template>
          </el-table-column>
          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           prop="mentorQuota"
                           header-align="center"
                           label="导师可录取人数">
            <template slot-scope="scope">
              {{ scope.row.mentorquota }}
            </template>
          </el-table-column>

          <el-table-column width="100px"
                           :align="contents.tableAlign"
                           v-if="!hasSubmit"
                           header-align="center"
                           label="操作">
            <template v-slot="scope">

              <el-button v-show='!hasSubmit' :type=scope.row.type size="mini"
                         @click='select(scope.row.mentorname,scope.row.id)'>
                {{scope.row.type === "success" ? '选择' : "已选择"}}
              </el-button>

              <el-dialog
                  :visible.sync="isSelectionDialogVisible"
                  title="确认选择"
                  width="25%">
                <p>选择导师 {{ name }} 作为你的</p>
                <el-select v-model="selectedChoice" placeholder="请选择志愿">
                  <el-option label="一志愿" value="1"></el-option>
                  <el-option label="二志愿" value="2"></el-option>
                  <el-option label="三志愿" value="3"></el-option>
                </el-select>
                <span slot="footer" class="dialog-footer">
                  <el-button @click="isSelectionDialogVisible = false">取消</el-button>
                  <el-button type="primary" @click="confirmSelection">确定</el-button></span>
              </el-dialog>

            </template>
          </el-table-column>
        </el-table>
        <el-pagination
            clsss="pages"
            :layout="layouts"
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="Number(contents.pageEachNum)"
            :total="totalPage"
            :small="contents.pageStyle"
            class="pagination-content"
            :background="contents.pageBtnBG"
            :style="{textAlign:contents.pagePosition==1?'left':contents.pagePosition==2?'center':'right'}"
        ></el-pagination>
      </div>
    </div>
    <!-- 添加/修改页面  将父组件的search方法传递给子组件-->
    <add-or-update v-if="addOrUpdateFlag" :parent="this" ref="addOrUpdate"></add-or-update>

  </div>
</template>
<script>
import AddOrUpdate from "./add-or-update";
import updatePassword from "@/views/update-password.vue";

export default {
  data() {
    return {
      searchForm: {
        key: ""
      },
      hasSubmit: '',

      selectionCount: 0,
      form: {},
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      showFlag: true,
      sfshVisiable: false,
      shForm: {},
      chartVisiable: false,
      addOrUpdateFlag: false,
      contents: {
        "searchBtnFontColor": "rgba(49,47,47,0.88)",
        "pagePosition": "1",
        "inputFontSize": "14px",
        "inputBorderRadius": "5px",
        "tableBtnDelFontColor": "#333",
        "searchBtnHeight": "40px",
        "inputIconColor": "#C0C4CC",
        "searchBtnBorderRadius": "5px",
        "tableStripe": false,
        "tableBtnDelBgColor": "rgba(214, 186, 232, 1)",
        "tableSize": "medium",
        "searchBtnBorderStyle": "solid",
        "tableSelection": true,
        "searchBtnBorderWidth": "1px",
        "tableContentFontSize": "14px",
        "searchBtnBgColor": "rgba(218,229,223,0.66)",
        "inputTitleSize": "16px",
        "pageJumper": true,
        "tableBtnDetailFontColor": "#333",
        "tableBtnHeight": "40px",
        "pagePager": true,
        "searchBtnBorderColor": "#DCDFE6",
        "tableHeaderFontColor": "rgba(47,44,44,0.76)",// 列首字体颜色
        "tableBtnBorderRadius": "5px",

        "btnAdAllDelFontColor": "#333",
        "btnAdAllWarnFontColor": "#ffffff",// 字体颜色
        "btnAdAllBorderColor": "#b2ac68",// 左上按钮边框颜色
        "btnAdAllHeight": "40px",
        "btnAdAllWarnBgColor": "rgba(75,222,146,0.8)",
        "btnAdAllFontWeight": 550,
        "btnAdAllBorderWidth": "1px",

        "tableStripeFontColor": "#606266",
        "tableBtnBorderStyle": "solid",
        "inputHeight": "40px",
        "btnAdAllBorderRadius": "5px",
        "btnAdAllDelBgColor": "rgba(255, 76, 10, 0.71)",
        "pagePrevNext": true,
        "btnAdAllAddBgColor": "rgba(242, 225, 132, 1)",
        "searchBtnFont": "1",
        "tableIndex": true,
        "btnAdAllIcon": "1",
        "tableSortable": true,
        "pageSizes": true,
        "tableFit": true,
        "pageBtnBG": true,
        "searchBtnFontSize": "14px",
        "tableBtnEditBgColor": "rgba(202, 235, 202, 1)",
        "inputBorderWidth": "1px",
        "inputFontPosition": "2",
        "inputFontColor": "#333",
        "pageEachNum": 10,
        "tableHeaderBgColor": "rgb(255,255,255)",//列首背景
        "inputTitleColor": "rgba(54,55,58,0.88)",
        "btnAdAllBoxPosition": "1",
        "tableBtnDetailBgColor": "rgba(173, 241, 242, 1)",
        "inputIcon": "0",
        "searchBtnIconPosition": "1",
        "btnAdAllFontSize": "14px",
        "inputBorderStyle": "solid",
        "inputBgColor": "rgba(255,255,255,0.66)",
        "pageStyle": false,
        "pageTotal": true,
        "btnAdAllAddFontColor": "#333",
        "tableBtnFont": "1",
        "tableContentFontColor": "#29292f",//表格内字体
        "inputBorderColor": "#DCDFE6",
        "tableShowHeader": true,
        "tableBtnFontSize": "14px",
        "tableBtnBorderColor": "#DCDFE6",
        "inputIconPosition": "1",
        "tableBorder": true,
        "btnAdAllBorderStyle": "solid",
        "tableBtnBorderWidth": "1px",
        "tableStripeBgColor": "#F5F7FA",
        "tableBtnEditFontColor": "#333",
        "tableAlign": "center"
      },
      layouts: '',


      isSelectionDialogVisible: false,
      selectedChoice: '1', // 默认为一志愿
      id: '', //存储导师id
      name: '1', // 存储导师姓名
      hasChoice: [], //存储以及选择

      transData: {
        firstchoice: '',
        firstname: '',
        firstid: '',
        firststate: false,

        secondchoice: '',
        secondname: '',
        secondid: '',
        secondstate: false,

        thirdchoice: '',
        thirdname: '',
        thirdid: '',
        thirdstate: false,
      },

      transDataVo: {
        firstchoice: '',
        secondchoice: '',
        thirdchoice: '',
      }

    };
  },
  created() {
    this.getDataList();
    this.contentStyleChange()
    this.getSubmit()
  },
  mounted() {

  },
  filters: {
    htmlfilter: function (val) {
      return val.replace(/<[^>]*>/g).replace(/undefined/g, '');
    }
  },
  components: {
    AddOrUpdate,
  },

  methods: {
    //提交表单
    submit() {
      this.transDataVo.firstchoice = this.transData.firstchoice;
      this.transDataVo.secondchoice = this.transData.secondchoice;
      this.transDataVo.thirdchoice = this.transData.thirdchoice;

      // 显示确认对话框
      this.$confirm('您确定要提交选择吗？', '确认提交', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 用户点击确定后执行提交
        this.$http({
          url: "student/submit-choices",
          method: "post",
          data: this.transDataVo
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message.success(data.message || "提交成功"); // 返回角色数据
            this.getSubmit()
          } else {
            console.error("提交失败", data.message);
            throw new Error(data.message || "提交失败");
          }
        }).catch(error => {
          console.error("请求出错", error);
          throw error; // 重新抛出错误以便上层处理
        });
      }).catch(() => {
        // 用户点击取消时的处理
        this.$message.info('提交已取消');
      });
    },


    //选择导师
    select(name, id) {
      if (!this.hasChoice.find(item => item === id)) {
        this.name = name; // 设置导师姓名
        this.id = id
        this.isSelectionDialogVisible = true; // 显示弹窗
      } else {
        this.$message.error("该导师已被选择")
      }

    },

    //退回选择
    cancelFi() {
      this.hasChoice = this.hasChoice.filter(item => item !== this.transData.firstchoice)
      this.transData.firststate = false
      this.transData.firstname = ''
      this.transData.firstchoice = ''
      this.updateType();
    },

    cancelSe() {
      this.hasChoice = this.hasChoice.filter(item => item !== this.transData.secondchoice)
      this.transData.secondstate = false
      this.transData.secondname = ''
      this.transData.secondchoice = ''
      this.updateType();
    },

    cancelTh() {
      this.hasChoice = this.hasChoice.filter(item => item !== this.transData.thirdchoice)
      this.transData.thirdstate = false
      this.transData.thirdname = ''
      this.transData.thirdchoice = ''
      this.updateType();
    },

    contentStyleChange() {
      this.contentSearchStyleChange()
      this.contentBtnAdAllStyleChange()
      this.contentSearchBtnStyleChange()
      this.contentPageStyleChange()
    },
    contentSearchStyleChange() {
      this.$nextTick(() => {
        document.querySelectorAll('.form-content .slt .el-input__inner').forEach(el => {
          let textAlign = 'left'
          if (this.contents.inputFontPosition == 2) textAlign = 'center'
          if (this.contents.inputFontPosition == 3) textAlign = 'right'
          el.style.textAlign = textAlign
          el.style.height = this.contents.inputHeight
          el.style.lineHeight = this.contents.inputHeight
          el.style.color = this.contents.inputFontColor
          el.style.fontSize = this.contents.inputFontSize
          el.style.borderWidth = this.contents.inputBorderWidth
          el.style.borderStyle = this.contents.inputBorderStyle
          el.style.borderColor = this.contents.inputBorderColor
          el.style.borderRadius = this.contents.inputBorderRadius
          el.style.backgroundColor = this.contents.inputBgColor
        })
        if (this.contents.inputTitle) {
          document.querySelectorAll('.form-content .slt .el-form-item__label').forEach(el => {
            el.style.color = this.contents.inputTitleColor
            el.style.fontSize = this.contents.inputTitleSize
            el.style.lineHeight = this.contents.inputHeight
          })
        }
        setTimeout(() => {
          document.querySelectorAll('.form-content .slt .el-input__prefix').forEach(el => {
            el.style.color = this.contents.inputIconColor
            el.style.lineHeight = this.contents.inputHeight
          })
          document.querySelectorAll('.form-content .slt .el-input__suffix').forEach(el => {
            el.style.color = this.contents.inputIconColor
            el.style.lineHeight = this.contents.inputHeight
          })
          document.querySelectorAll('.form-content .slt .el-input__icon').forEach(el => {
            el.style.lineHeight = this.contents.inputHeight
          })
        }, 10)

      })
    },
    // 搜索按钮
    contentSearchBtnStyleChange() {
      this.$nextTick(() => {
        document.querySelectorAll('.form-content .slt .el-button--success').forEach(el => {
          el.style.height = this.contents.searchBtnHeight
          el.style.color = this.contents.searchBtnFontColor
          el.style.fontSize = this.contents.searchBtnFontSize
          el.style.borderWidth = this.contents.searchBtnBorderWidth
          el.style.borderStyle = this.contents.searchBtnBorderStyle
          el.style.borderColor = this.contents.searchBtnBorderColor
          el.style.borderRadius = this.contents.searchBtnBorderRadius
          el.style.backgroundColor = this.contents.searchBtnBgColor
        })
      })
    },
    // 新增、批量删除
    contentBtnAdAllStyleChange() {
      this.$nextTick(() => {
        document.querySelectorAll('.form-content .ad .el-button--success').forEach(el => {
          el.style.height = this.contents.btnAdAllHeight
          el.style.color = this.contents.btnAdAllAddFontColor
          el.style.fontSize = this.contents.btnAdAllFontSize
          el.style.borderWidth = this.contents.btnAdAllBorderWidth
          el.style.borderStyle = this.contents.btnAdAllBorderStyle
          el.style.borderColor = this.contents.btnAdAllBorderColor
          el.style.borderRadius = this.contents.btnAdAllBorderRadius
          el.style.backgroundColor = this.contents.btnAdAllAddBgColor
        })
        document.querySelectorAll('.form-content .ad .el-button--danger').forEach(el => {
          el.style.height = this.contents.btnAdAllHeight
          el.style.color = this.contents.btnAdAllDelFontColor
          el.style.fontSize = this.contents.btnAdAllFontSize
          el.style.borderWidth = this.contents.btnAdAllBorderWidth
          el.style.borderStyle = this.contents.btnAdAllBorderStyle
          el.style.borderColor = this.contents.btnAdAllBorderColor
          el.style.borderRadius = this.contents.btnAdAllBorderRadius
          el.style.backgroundColor = this.contents.btnAdAllDelBgColor
        })
        document.querySelectorAll('.form-content .ad .el-button--warning').forEach(el => {
          el.style.height = this.contents.btnAdAllHeight
          el.style.color = this.contents.btnAdAllWarnFontColor
          el.style.fontSize = this.contents.btnAdAllFontSize
          el.style.fontWeight = this.contents.btnAdAllFontWeight
          el.style.borderWidth = this.contents.btnAdAllBorderWidth
          el.style.borderStyle = this.contents.btnAdAllBorderStyle
          el.style.borderColor = this.contents.btnAdAllBorderColor
          el.style.borderRadius = this.contents.btnAdAllBorderRadius
          el.style.backgroundColor = this.contents.btnAdAllWarnBgColor
        })
      })
    },
    // 表格
    rowStyle({row, rowIndex}) {
      if (rowIndex % 2 == 1) {
        if (this.contents.tableStripe) {
          return {color: this.contents.tableStripeFontColor}
        }
      } else {
        return ''
      }
    },

    cellStyle({row, rowIndex}) {
      if (rowIndex % 2 == 1) {
        if (this.contents.tableStripe) {
          return {backgroundColor: this.contents.tableStripeBgColor}
        }
      } else {
        return ''
      }
    },

    headerRowStyle({row, rowIndex}) {
      return {color: this.contents.tableHeaderFontColor}
    },
    headerCellStyle({row, rowIndex}) {
      return {backgroundColor: this.contents.tableHeaderBgColor}
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandler(val) {
      this.dataListSelections = val;
    },
    indexMethod(index) {
      return (Number(this.pageIndex) - 1) * Number(this.pageSize) + index + 1;
    },

    // 分页
    contentPageStyleChange() {
      let arr = []

      if (this.contents.pageTotal) arr.push('total')
      if (this.contents.pageSizes) arr.push('sizes')
      if (this.contents.pagePrevNext) {
        arr.push('prev')
        if (this.contents.pagePager) arr.push('pager')
        arr.push('next')
      }
      if (this.contents.pageJumper) arr.push('jumper')
      this.layouts = arr.join()
      this.contents.pageEachNum = 10
    },

    search() {
      this.pageIndex = 1;
      console.log()
      this.getDataList();
    },
    // 获取数据列表

    updateType() {
      this.dataList.forEach(item => {
        item.type = 'success';
      })
      this.hasChoice.forEach(choice => {
        // 找到 dataList 中对应 ID 的对象
        this.dataList.forEach(dataItem => {
          if (dataItem.id === choice) {
            dataItem.type = 'info'
          }
        })
      })
    },

    getDataList() {
      this.dataListLoading = true;
      let params = {
        current: this.pageIndex,
        gender: "",
        id: 0,
        mentoraccount: "",
        mentorcollege: "",
        mentorname: "",
        pageSize: this.pageSize,
        sortField: "",
        sortOrder: "",
        unionid: "",
      }
      if (this.searchForm.mentorname != '' && this.searchForm.mentorname != undefined) {
        params['mentorname'] = this.searchForm.mentorname
      }
      if (this.searchForm.mentoraccount != '' && this.searchForm.mentoraccount != undefined) {
        params['mentoraccount'] = this.searchForm.mentoraccount
      }
      this.$http({
        url: "student/list/page",
        method: "post",
        data: params
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.data.records.map(item => {
            return {
              ...item,
              type: "success", // 添加新属性
            };
          });
          this.totalPage = Number(data.data.total);
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },

    //选择检查
    confirmSelection(row) {
      // 检查第一个选择的状态
      if (this.selectedChoice === '1') {
        if (this.transData.firststate === true) {
          // 弹出确认对话框
          this.$confirm('一志愿已存在，是否替换？', '确认替换', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning'
          }).then(() => {
            // 用户点击了确认
            this.hasChoice = this.hasChoice.filter(item => item !== this.transData.firstchoice)//删除原来在列表中的id
            this.transData.firstchoice = this.id;
            this.hasChoice.push(this.transData.firstchoice)//重新添加id
            this.transData.firstname = this.name;
            this.updateType();
            // 弹出成功消息
            this.$message.success(`您已选择导师 ${this.name} 作为您的第${this.selectedChoice}志愿。`);
          })
              .catch(() => {
                // 用户点击了取消
                this.$message.info('您取消了替换操作');
              });
        } else {
          // 如果没有选择过，直接赋值
          this.hasChoice.push(this.id)
          this.transData.firstchoice = this.id;
          this.transData.firstname = this.name;
          this.transData.firststate = true; // 更新状态为已选择
          this.updateType();
        }
      } else if (this.selectedChoice === '2') {
        if (this.transData.secondstate === true) {
          // 弹出确认对话框
          this.$confirm('二志愿已存在，是否替换？', '确认替换', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning'
          }).then(() => {
            // 用户点击了确认
            this.hasChoice = this.hasChoice.filter(item => item !== this.transData.secondchoice)//删除原来在列表中的id
            this.transData.secondchoice = this.id;
            this.hasChoice.push(this.transData.secondchoice)//重新添加id
            this.transData.secondname = this.name;
            this.updateType();
            // 弹出成功消息
            this.$message.success(`您已选择导师 ${this.name} 作为您的第${this.selectedChoice}志愿。`);
          })
              .catch(() => {
                // 用户点击了取消
                this.$message.info('您取消了替换操作');
              });
        } else {
          // 如果没有选择过，直接赋值
          this.hasChoice.push(this.id)
          this.transData.secondchoice = this.id;
          this.transData.secondname = this.name;
          this.transData.secondstate = true; // 更新状态为已选择
          this.updateType();
        }
      } else if (this.selectedChoice === '3') {
        if (this.transData.thirdstate === true) {
          // 弹出确认对话框
          this.$confirm('三志愿已存在，是否替换？', '确认替换', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning'
          }).then(() => {
            // 用户点击了确认
            this.hasChoice = this.hasChoice.filter(item => item !== this.transData.thirdchoice)//删除原来在列表中的id
            this.transData.thirdchoice = this.id;
            this.hasChoice.push(this.transData.thirdchoice)//重新添加id
            this.transData.thirdname = this.name;
            this.updateType();
            // 弹出成功消息
            this.$message.success(`您已选择导师 ${this.name} 作为您的第${this.selectedChoice}志愿。`);
          })
              .catch(() => {
                // 用户点击了取消
                this.$message.info('您取消了替换操作');
              });
        } else {
          // 如果没有选择过，直接赋值
          this.hasChoice.push(this.id)
          this.transData.thirdchoice = this.id;
          this.transData.thirdname = this.name;
          this.transData.thirdstate = true; // 更新状态为已选择
          this.updateType();
        }
      }
      // 关闭弹窗
      this.isSelectionDialogVisible = false;
    },

    getSubmit() {
      this.$http({
        url: 'student/had-submit-choices',
        method: 'get',
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.hasSubmit = data.data
        } else {
          this.$message.error("bad")
        }
      }).catch(error => {
        console.error("请求出错", error);
        throw error; // 重新抛出错误以便上层处理
      });
    },
  },
}
</script>
<style lang="scss" scoped>

/deep/ .el-dialog__body {
  padding: 0;
}

/deep/ .dialogForm .form-outer {
  padding: 0 20px;

  .form-inner {
    padding: 0;
  }
}

.slt {
  margin: 0 !important;
  display: flex;
}

.fade-enter-active, .fade-leave-active {
  transition: opacity 1s;
}

.fade-enter, .fade-leave-to {
  opacity: 0;
}


.ad {
  margin: 0 !important;
  display: flex;
}

.pages {
  & /deep/ el-pagination__sizes {
    & /deep/ el-input__inner {
      height: 22px;
      line-height: 22px;
    }
  }
}


.el-button + .el-button {
  margin: 0;
}

.tables {


  & /deep/ .el-button--success {
    height: 40px;
    color: #ffffff;
    font-size: 14px;
    border-width: 1px;
    border-style: solid;
    border-color: #DCDFE6;
    border-radius: 5px;
    background-color: rgb(35, 223, 227);
  }

  & /deep/ .el-button--info {
    height: 40px;
    color: #ffffff;
    font-size: 14px;
    border-width: 1px;
    border-style: solid;
    border-color: #DCDFE6;
    border-radius: 5px;
    background-color: rgb(131, 146, 147);
  }

  & /deep/ .el-button--primary {
    height: 40px ;
    color: #333;
    font-size: 14px;
    border-width: 1px;
    border-style: solid;
    border-color: #DCDFE6;
    border-radius: 20px;
    background-color: rgba(202, 235, 202, 1);
  }

  & /deep/ .el-button--danger {
    height: 40px;
    color: #333;
    font-size: 14px;
    border-width: 1px;
    border-style: solid;
    border-color: #DCDFE6;
    border-radius: 20px;
    background-color: rgba(214, 186, 232, 1);
  }

  & /deep/ .el-button {
    margin: 4px;
  }
}

</style>
